package com.xy.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannel02 {
    public static void main(String[] args) throws IOException {
        File file = new File("/tmp/test.txt");
        FileInputStream fis = new FileInputStream(file);
        FileChannel fileChannel = fis.getChannel();
        ByteBuffer bb = ByteBuffer.allocate((int) file.length());
        fileChannel.read(bb);
        System.out.println(new String(bb.array()));
        fis.close();
    }
}
